import UploadImg from '../../components/UploadImg'
import React, { Component } from 'react'
import Add from './AddCo.module.css'
import { Button, Input, notification } from 'antd'
import { withRouter } from 'react-router-dom'
import { send } from '../../api/community'
import { SmileOutlined } from '@ant-design/icons';
const { TextArea } = Input;

class AddCo extends Component {
  constructor(props) {
    super(props)
  }
  state={
    url:'',
    mtext:''
  }
  getImg(url){
    this.setState({url})
  }
  submitCo() {
    console.log(this.state)
    send({
      mtext:this.state.mtext,
      uid:1,
      pid:1,
      label:'裤子',
      likenumber:0,
      username:'zhangsan',
      image:'',
      scancount:0,
      del:0,
      photo1:this.state.url
    }).then(res => {
      console.log(res, 'send')
      notification.open({
        message: 'OK',
        description:
          '恭喜你，动态发表成功',
        icon: <SmileOutlined style={{ color: '#108ee9' }} />,
      });
      this.props.history.push('/Community')
    })
  }
  render() {
    return (
      <div className={Add.container}>
        <div className={Add.header}>
          <Button type="text" onClick={() => { this.props.history.push('/Community') }}>取消</Button>
          <Button type="primary" onClick={() => { this.submitCo() }}>发表</Button>
        </div>

        <div className={Add.info}>
          <TextArea
            row={5}
            bordered={false}
            defaultValue={'...你想说点什么'}
            allowClear={true}
            showCount={true}
            onChange={(value)=>{this.state.mtext = value.target.value}}
            autoSize={{ minRows: 2, maxRows: 6 }}
          ></TextArea>
          <UploadImg concat={this.getImg.bind(this)} className={Add.upload}></UploadImg>
        </div>
      </div>
    )
  }
}
export default withRouter(AddCo)
